﻿using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp;

namespace EcoSystem.DataPermissions;

/// <summary>
/// 数据权限配置管理控制器
/// </summary>
[Area(EcoSystemRemoteServiceConsts.ModuleName)]
[RemoteService(Name = EcoSystemRemoteServiceConsts.RemoteServiceName)]
[Route("api/Platform/dataPermissionManager")]
public class DataPermissionManagerController : EcoSystemController, IDataPermissionManager
{
    private readonly IDataPermissionManager _service;

    public DataPermissionManagerController(IDataPermissionManager service)
    {
        _service = service;
    }

    /// <summary>
    /// 删除指定的业务权限数据
    /// </summary>
    /// <param name="providerName"></param>
    /// <param name="providerKey"></param>
    /// <param name="enCode"></param>
    /// <returns></returns>
    /// <exception cref="System.NotImplementedException"></exception>
    [HttpDelete]
    public async Task DeleteAsync(string providerName, string providerKey, string enCode)
    {
        await _service.DeleteAsync(providerName, providerKey, enCode);
    }

    /// <summary>
    /// 获取指定业务权限数据
    /// </summary>
    /// <param name="providerName"></param>
    /// <param name="providerKey"></param>
    /// <param name="enCode"></param>
    /// <returns></returns>
    /// <exception cref="System.NotImplementedException"></exception>
    [HttpGet]
    [Route("getPermissions")]
    public async Task<List<DataPermissionGrantDto>> GetPermissionsAsync(string providerName, string providerKey, string enCode)
    {
        return await _service.GetPermissionsAsync(providerName, providerKey, enCode);
    }

    [NonAction]
    public async Task<bool> IsGrantedAsync(string enCode, string dataId)
    {
        return await _service.IsGrantedAsync(enCode, dataId);
    }

    /// <summary>
    /// 保存权限熂
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    /// <exception cref="System.NotImplementedException"></exception>
    [HttpPost]
    [Route("savePermissions")]
    public async Task<List<DataPermissionGrantDto>> SavePermissionsAsync(SaveDataPermissionGrantsInputDto input)
    {
        return await _service.SavePermissionsAsync(input);
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    /// <exception cref="System.NotImplementedException"></exception>
    [HttpPost]
    public async Task SetAsync(SetDataPermissionInputDto input)
    {
        await _service.SetAsync(input);
    }
}